package ir;


public class Value {
	/**
     * 存储值对象的类型,常量存储在Symbol中
     * mType决定应当调用哪一种的变量
     * 序号分别是0,1,2,3,4
     */
	public static final int INT=1, DOUBLE=2,BOOL=3;
    public int mType;

    public int mInt;
    public double mDouble;
    public boolean mBool;

    public Value(int i){
        mType = i;
    }
    public Value(int i, int j){
        mType = i;mInt = j;
    }
    public Value(int i, double j){
        mType = i;mDouble = j;
    }
    public Value(int i, boolean j){
        mType = i;mBool = j;
    }

    public double getValue(){
        switch (mType){
            case INT:
                return mInt;
            case DOUBLE:
                return mDouble;
            case BOOL:
                if(mBool==true)
                    return 1;
                return 0;
        }
        return mDouble;
    }

    public void setValue(Value v){
        switch (v.mType) {
            case DOUBLE:
                mType = DOUBLE;
                fresh();
                mDouble = v.mDouble;
                break;
            case INT:
                if (mType != DOUBLE) {
                    mType = INT;
                    fresh();
                    mInt = v.mInt;
                } else {
                    mDouble = v.mInt;
                }
                break;
            case BOOL:
                switch (mType) {
                    case INT:
                        mInt = (int)(v.getValue());
                        break;
                    case DOUBLE:
                        mDouble = v.getValue();
                        break;
                    case BOOL:
                        mBool = v.mBool;
                        break;
                }
                break;
        }

    }
    public void fresh(){
        mInt=0;
        mDouble=0;
        mBool=false;
    }
}
